<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>支付设置</title>
    {template 'stourtravel/public/public_min_js'}
    {Common::getCss('style.css,base.css,base_new.css')}
    {Common::getScript('jquery.upload.js')}
</head>
<body>

<table class="content-tab">
    <tr>
        <td width="119px" class="content-lt-td"  valign="top">
            {template 'stourtravel/public/leftnav'}
            <!--右侧内容区-->
        </td>
        <td valign="top" class="content-rt-td">
            <div class="cfg-header-bar">
                <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
            </div>
            <div class="clear clearfix">
                <form id="frm">
                    <div class="pay-container" >
                        <ul class="info-item-block">
                            <li>
                                <span class="item-hd">策略名称：</span>
                                <div class="item-bd">
                                    <input name="name" type="text" value="{$info['name']}" class="input-text w300">
                                </div>
                            </li>
                            <li>
                                <span class="item-hd">策略规则：</span>
                                <div class="item-bd">
                                    <span class="select-box w70">
                                        <select size="1" name="type" class="select">
                                            <option {if $info['type']==1}selected="selected"{/if} value="1">加价</option>
                                            <option {if $info['type']==2}selected="selected"{/if} value="2">减价</option>
                                        </select>
                                    </span>
                                    <span class="select-box w90">
                                        <select onchange="type_change($(this))" size="1" name="value_type" class="select value-type">
                                            <option {if $info['value_type']==1}selected="selected"{/if} value="1">百分比</option>
                                            <option {if $info['value_type']==2}selected="selected"{/if} value="2">固定金额</option>
                                        </select>
                                    </span>
                                    <input type="text" name="value" value="{$info['value']}" class="input-text w150" onkeyup="number($(this))" placeholder="请输入1-100的数字">
                                </div>
                            </li>
                            <li>
                                <span class="item-hd">是否开启：</span>
                                <div class="item-bd">
                                    <label class="radio-label mr-20">
                                        <input type="radio" {if $info['is_open']==1}checked="checked"{/if} name="is_open" value="1">开启
                                    </label>
                                    <label class="radio-label">
                                        <input type="radio" {if !$info['is_open']}checked="checked"{/if} name="is_open" value="0">关闭
                                    </label>
                                </div>
                            </li>
                        </ul>
                    </div>
                    <div class="clear clearfix mt-20">
                        <a class="btn btn-primary radius size-L ml-115" href="javascript:;" id="btn_save">保存</a>
                    </div>
                    <input type="hidden" name="id" value="{$info['id']}">
                    <input type="hidden" name="type_id" value="{$type_id}">
                </form>
            </div>
        </td>
    </tr>
</table>

<script>
    //限制不同类型的数字输入方式
    function number(obj)
    {
        var value_type =  $('.value-type option:selected').val();
        var val = obj.val();
        if(value_type==1){
            val = val.replace(/[^\d]/g,'').replace(/^0{1,}/g,'')
            val = val>100?'':val;
        }else{
            val = val.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')
        }
        obj.val(val);
    }

    //切换提示语
    function type_change(obj)
    {
        var val = obj.val();
        if(val==1){
            $("[name='value']").attr('placeholder','请输入1-100的数字');
        }else{
            $("[name='value']").attr('placeholder','请输入大于0的数字');
        }
    }

    $(document).ready(function(){
        $("#btn_save").click(function(){
            $.ajaxform({
                url   :  SITEURL+"ebooking/ajax_sale_save_sale",
                method  :  "POST",
                form  : "#frm",
                dataType:'json',
                success  :  function(data)
                {
                    if(data.status)
                    {
                        $("[name='id']").val(data.id);
                        ST.Util.showMsg('保存成功!','4',2000);
                    }
                    else
                    {
                        ST.Util.showMsg(data.msg,'5',2000);
                    }
                }
            },'JSON');
        });
    });
</script>

</body>
</html>
